package com.tiantian.common.satoken.utils;

import com.tiantian.common.core.domain.model.BaseEntity;
import lombok.Data;

import java.time.LocalDateTime;

import static com.tiantian.common.satoken.utils.LoginHelper.getNickName;

/**
 * @author tiantian
 */
@Data
public class FieldUtils {
    /**
     * 公共字段填充 更新操作
     */
    public static void updateCommonFields(BaseEntity baseEntity) {
        baseEntity.setUpdateBy(getNickName());
        baseEntity.setUpdateTime(LocalDateTime.now());

    }

    /**
     * 公共字段填充 插入操作
     */
    public static void insertAndSetCommonFields(BaseEntity baseEntity) {
        String nickName = getNickName();
        baseEntity.setCreateBy(nickName);
        baseEntity.setCreateTime(LocalDateTime.now());
        baseEntity.setUpdateBy(nickName);
        baseEntity.setUpdateTime(LocalDateTime.now());
    }
}
